package com.biwin.core.main.config;

import com.biwin.core.api.interceptor.IBwHandlerInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * BiWin Framework Common Interceptor
 * <p>
 * Set OnlineUserInfo Properties in Session
 *
 * @author biwin
 * @since 0.0.1
 */
@Configuration
public class BwWebMvcConfiguration implements WebMvcConfigurer {
    private final IBwHandlerInterceptor bwHandlerInterceptor;

    public BwWebMvcConfiguration(IBwHandlerInterceptor bwHandlerInterceptor) {
        this.bwHandlerInterceptor = bwHandlerInterceptor;
    }

    /**
     * Override this method to add Spring MVC interceptors for
     * pre- and post-processing of controller invocation.
     *
     * @param registry
     * @see InterceptorRegistry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(bwHandlerInterceptor).addPathPatterns("/**")
        ;
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // 禁用Swagger自带的UI,使用knife4j提供的UI
        registry.addRedirectViewController("/", "/doc.html");
        registry.addRedirectViewController("/swagger-ui/", "/doc.html");
        registry.addRedirectViewController("/swagger-ui/index.html", "/doc.html");
    }

}
